package model;

import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ColourTableCellRenderer extends DefaultTableCellRenderer {
	private static final long serialVersionUID = 8141610984131738686L;
	
	/* Constructor */
	public ColourTableCellRenderer() {
		/* The text of all cells will be centered */
        setHorizontalAlignment( CENTER );
    }

    public Component getTableCellRendererComponent(
        JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    {
        Component comp = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        
        /* Current cell value */
        String s = (String) value;
        /* Colour discrimination cell value of the current row */
        String x = (String) table.getValueAt(row, 1);
        
        /* For each type of log a different colour is set to the complete row */
        if(s.equalsIgnoreCase("WARN") || x.equalsIgnoreCase("WARN")) {
        	setBackground(Color.YELLOW);
        	comp.setForeground(Color.BLACK);
    	}
        else if(s.equalsIgnoreCase("INFO") || x.equalsIgnoreCase("INFO")) {
        	setBackground(Color.CYAN);
        	setForeground(Color.BLACK);
        }
        else if(s.equalsIgnoreCase("ERROR") || x.equalsIgnoreCase("ERROR")) {
        	setBackground(Color.RED);
        	setForeground(Color.WHITE);
        }
        else if(s.equalsIgnoreCase("FATAL") || x.equalsIgnoreCase("FATAL")) {
        	setBackground(Color.BLACK);
        	setForeground(Color.WHITE);
        }
        else if(s.equalsIgnoreCase("USE") || x.equalsIgnoreCase("USE")) {
        	setBackground(Color.WHITE);
        	setForeground(Color.BLUE);
        }
        else if(s.equalsIgnoreCase("DEBUG") || x.equalsIgnoreCase("DEBUG")) {
        	setBackground(new Color(0xD0F5A9));
        	setForeground(Color.BLACK);
        }
        
        else {
        	setBackground(Color.WHITE);
        	comp.setForeground(Color.BLACK);
        }
        
        /* If the row is selected... */
        if(isSelected) {
        	//setBackground(Color.BLUE);
        	//setForeground(Color.WHITE);
        }
        
        return comp;
    }
}
